package com.blackfish.active;
import java.util.List;

import com.blackfish.common.model.Active;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;


public class ActiveService {
	public static final Active dao = new Active().dao();
	
	public String getNameById(int id){
			return this.findById(id).getName();
	}
	public int getIdByName(String name){
		return dao.findFirst("select * from active where name='"+name+"'").getId();
	}
	
	public List<Active> findAll(){
		return dao.find("select * from active order by id asc");
	}
	
	public List<Active> findByStyle(String style){
		return dao.find("select * from active where style ="+ style +" order by id asc");
	}
	
	public Active findById(int id) {
		return dao.findById(id);
	}
	
	public void deleteById(int id) {
		dao.deleteById(id);
	}
	
	public String findByViewname(String viewName){
		return dao.findFirst("select * from active where viewname=\""+ viewName+"\"").getName();
	}

	public List<Record> findAllView(){
		return Db.find("select a.id,a.name,a.viewname,s.viewname as style from active as a inner join style as s on s.id=a.style");
	}
}
